<template>
	<el-dialog
		:title="title"
		:visible.sync="addComShow"
		width="35%"
		:before-close="cancel"
		:close-on-click-modal="false"
		:close-on-press-escape="false"
	>
		<el-form ref="form" label-width="120px" label-position="left">
			<el-form-item label="产品内部代码：" required>
				<el-input v-model="fundManagerForm.fundCode" disabled></el-input>
			</el-form-item>
			<el-form-item label="产品名称：" required>
				<el-input v-model="fundManagerForm.fundFullName" disabled></el-input>
			</el-form-item>
			<el-form-item label="责任人：" required>
				<el-select style="width: 100%" v-model="fundManagerForm.personLiableId" filterable>
					<el-option key="" label="--请选择--" value=""> </el-option>
					<el-option v-for="(item, index) in commonPersonList" :key="index" :label="item.firstName" :value="item.username"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="复核人：" required>
				<el-select style="width: 100%" v-model="fundManagerForm.checkLiableId" filterable>
					<el-option v-for="(item, index) in commonCheckList" :key="index + 'a'" :label="item.firstName" :value="item.username"></el-option>
				</el-select>
			</el-form-item>
		</el-form>
		<span slot="footer" class="dialog-footer">
			<el-button @click="cancel" size="small">取 消</el-button>
			<el-button type="primary" @click="addConfirm" size="small">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
import { saveFundInfo } from '@/api/productApi/admiSystem'
import { departmentUser } from '@/api/productApi/fundManager'
export default {
	props: {
		title: {
			type: String,
			default: ''
		},
		addComShow: {
			type: Boolean,
			default: false
		},
		comIsShow: {
			type: Function,
			default: Function
		},
		queryFundManagerList: {
			type: Function,
			default: Function
		}
	},
	data() {
		return {
			fundManagerForm: {},
			commonPersonList: [], // 责任人
			commonCheckList: [] // 复核人
		}
	},
	mounted() {
		this.getUserOpList()
	},
	methods: {
		cancel() {
			this.$emit('comIsShow')
			this.fundManagerForm = {}
		},
		edit(obj) {
			this.fundManagerForm = JSON.parse(obj)
		},
		// 查询：获取拥有某权限的用户信息
		getUserOpList() {
			departmentUser({ userCode: '2', userList: [] }).then(res => {
				if (res.msgCode === 'Y') {
					const data = res.data.body
					this.commonCheckList = data
					this.commonPersonList = data
				} else {
					this.$message({ message: res.msgDesc, customClass: 'el-messageClass', type: 'error' })
				}
			})
		},
		// 新增或编辑
		addConfirm() {
			if (!!this.fundManagerForm.personLiableId && !!this.fundManagerForm.checkLiableId) {
				saveFundInfo(this.fundManagerForm).then(res => {
					if (res.msgCode === 'Y') {
						this.$message({
							showClose: true,
							message: '修改成功',
							customClass: 'el-messageClass',
							type: 'success'
						})
						this.$emit('queryFundManagerList')
						this.cancel()
					}
				})
			} else {
				this.$message({ type: 'warning', customClass: 'el-messageClass', message: '请正确填写必要参数' })
			}
		}
	}
}
</script>
<style lang="scss" scoped >
</style>
